package com.spic.business.informatization.meeting.controller;

import com.spic.business.informatization.meeting.domain.MeetingActivity;
import com.spic.business.informatization.meeting.domain.MeetingActivityGroup;
import com.spic.business.informatization.meeting.dto.MeetingMeasureDTO;
import com.spic.business.informatization.meeting.service.IMeetingActivityService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * 工前会Controller
 * 
 * @author spic
 * @date 2021-11-04
 */
@RestController
@RequestMapping("informatization/meeting")
public class MeetingActivityController extends BaseController
{
    @Autowired
    private IMeetingActivityService meetingActivityService;

    /**
     * 查询工前会列表
     */
    @PreAuthorize(hasPermi = "informatization/meeting:meeting:list")
    @GetMapping("/list")
    public TableDataInfo list(MeetingActivity meetingActivity)
    {
        startPage();
        List<MeetingActivity> list = meetingActivityService.selectMeetingActivityList(meetingActivity);
        return getDataTable(list);
    }

    /**
     * 导出工前会列表
     */
    @PreAuthorize(hasPermi = "informatization/meeting:meeting:export")
    @Log(title = "工前会", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeetingActivity meetingActivity) throws IOException
    {
        List<MeetingActivity> list = meetingActivityService.selectMeetingActivityList(meetingActivity);
        ExcelUtil<MeetingActivity> util = new ExcelUtil<MeetingActivity>(MeetingActivity.class);
        util.exportExcel(response, list, "工前会数据");
    }

    /**
     * 获取工前会详细信息
     */
    @PreAuthorize(hasPermi = "informatization/meeting:meeting:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(meetingActivityService.selectMeetingActivityById(id));
    }

    /**
     * 新增工前会
     */
    @PreAuthorize(hasPermi = "informatization/meeting:meeting:add")
    @Log(title = "工前会", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeetingActivity meetingActivity)
    {
        return AjaxResult.success(meetingActivityService.insertMeetingActivity(meetingActivity));
    }

    /**
     * 删除工前会
     */
    @PreAuthorize(hasPermi = "informatization/meeting:meeting:remove")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(meetingActivityService.deleteMeetingActivityByIds(ids));
    }

    /**
     * 删除工前会小组信息
     */
    @DeleteMapping("/group/{ids}")
    public AjaxResult removeGroup(@PathVariable Long[] ids)
    {
        return toAjax(meetingActivityService.deleteMeetingActivityGroupByIds(ids));
    }

    /**
     * 新增工前会关联工作及措施
     */
    @Log(title = "工前会工作措施", businessType = BusinessType.INSERT)
    @PostMapping("/measure")
    public AjaxResult addMeasure(@RequestBody @Valid MeetingMeasureDTO measure)
    {
        return toAjax(meetingActivityService.insertMeetingActivityGroupWork(measure));
    }

    /**
     * 获取工前会详细信息
     */
    @GetMapping(value = "measure/{id}")
    public AjaxResult getWorkInfoByGropupId(@PathVariable("id") Long id)
    {
        return AjaxResult.success(meetingActivityService.getWorkInfoByGroupId(id));
    }

    /**
     * 生成工前会关联工作单
     */
    @PutMapping(value = "generate_ticket/{id}")
    public AjaxResult generateTicket(@PathVariable("id") Long id)
    {
        meetingActivityService.generateTicket(id);
        return AjaxResult.success();
    }

    /**
     * 新增工前会主表
     */
    @Log(title = "工前会主表", businessType = BusinessType.INSERT)
    @PostMapping("/group")
    public AjaxResult addMeasure(@RequestBody @Valid MeetingActivityGroup group)
    {
        return AjaxResult.success(meetingActivityService.saveGroup(group));
    }
}
